/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wasolicitudesfiec.dataproviders;

import com.sun.data.provider.DataProviderException;
import com.sun.data.provider.FieldKey;
import com.sun.data.provider.RowKey;
import com.sun.data.provider.impl.AbstractTableDataProvider;
import com.sun.data.provider.impl.IndexRowKey;
import entidad.Profesor;
import java.util.Vector;

/**
 *
 * @author Larry
 */
public class Dp_Profesor extends AbstractTableDataProvider {

    int numeroFilas = 20;
    private Vector<Profesor> listaProfesor = new Vector<Profesor>();

    public Dp_Profesor() {
        agregarKey("profesor", "Profesor");
        agregarKey("profesor_id", "");
        
          agregarKey("correo", "Correo");
       agregarKey("usuario", "Usuario");
        

    }

    public void setListaProfesor(Vector<Profesor> listaProfesor) {
        this.listaProfesor = listaProfesor;
//        numeroFilas = this.listaProfesor.size();
    }

    private void agregarKey(String key_string, String display_name) {
        FieldKey key;
        key = new FieldKey(key_string);
        key.setDisplayName(display_name);
        addFieldKey(key);
    }

    @Override
    public Class getType(FieldKey fieldKey) throws DataProviderException {
        return String.class;
    }

    @Override
    public boolean isReadOnly(FieldKey fieldKey) throws DataProviderException {
        return true;
    }

    @Override
    public int getRowCount() throws DataProviderException {
        return listaProfesor.size();
    }

    @Override
    public Object getValue(FieldKey fieldKey, RowKey row) throws DataProviderException {
        int indice = ((IndexRowKey) row).getIndex();
		if (fieldKey==null)
			return "";
		String fieldId = fieldKey.getFieldId();
        if (indice < this.listaProfesor.size()) {
            Profesor profesor = this.listaProfesor.get(indice);
            if (fieldId.equals("profesor")) {
                return profesor.getPersona().toString();
            }else if (fieldId.equals("profesor_id")){
                return profesor.getIdProfesor();
            }else if (fieldId.equals("correo")){
                return profesor.getPersona().getCorreo();
           }else if (fieldId.equals("usuario")){
                return profesor.getPersona().getUsuario();
            }
        }
        return "Hola";
    }

    @Override
    public void setValue(FieldKey fieldKey, RowKey row, Object value) throws DataProviderException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean canInsertRow(RowKey beforeRow) throws DataProviderException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public RowKey insertRow(RowKey beforeRow) throws DataProviderException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean canAppendRow() throws DataProviderException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public RowKey appendRow() throws DataProviderException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean canRemoveRow(RowKey row) throws DataProviderException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void removeRow(RowKey row) throws DataProviderException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void setRowCount(int numeroFilas) {
        this.numeroFilas = numeroFilas;
    }
}
